#ifndef process
#define process

typedef struct process
     {
       struct process *next;       /* next process in pipeline */
       char **argv;                /* for exec */
       pid_t pid;                  /* process ID */
       char completed;             /* true if process has completed */
       char stopped;               /* true if process has stopped */
       int status;                 /* reported status value */
     } process;

typedef struct job
     {
       struct job *next;           /* next active job */
       char *command;              /* command line, used for messages */
       process *first_process;     /* list of processes in this job */
       pid_t pgid;                 /* process group ID */
       char notified;              /* true if user told about stopped job */
       struct termios tmodes;      /* saved terminal modes */
       int stdin, stdout, stderr;  /* standard i/o channels */
     } job;

     /* Find the active job with the indicated pgid.  */

job * find_job (pid_t pgid){
       
	job *j;
     
       for (j = first_job; j; j = j->next)
         if (j->pgid == pgid)
           return j;
       
	return NULL;
}
/* Return true if all processes in the job have stopped or completed.  */
int job_is_stopped (job *j){
       
	process *p;
     
       for (p = j->first_process; p; p = p->next)
         if (!p->completed && !p->stopped)
           return 0;

       return 1;
}

     /* Return true if all processes in the job have completed.  */
int job_is_completed (job *j){
       
	process *p;
     
       for (p = j->first_process; p; p = p->next)
         if (!p->completed)
           return 0;
       
	return 1;
     }

/*colocando em forground*/
  
void put_job_in_foreground (trabalho * j, int cont)
     {
       / * Coloque o trabalho em primeiro plano. Dando acesso    * /
       tcsetpgrp (shell_terminal, j-> pgid);
     
       / * Enviar o trabalho de um sinal de continuar, se necessário.   * /
       if (cont)
         {
           tcsetattr (shell_terminal, TCSADRAIN, e j-> tmodes);
           if (kill (- j-> pgid, SIGCONT) <0)
             perror ("kill (SIGCONT)");
         }
     
       / * Espere até que o relatório.   * /
       wait_for_job (j);
     
       / * Coloque o shell de volta em primeiro plano.   * /
       tcsetpgrp (shell_terminal, shell_pgid);






     
       / * Restaurar modos do shell terminal.   * /
       tcgetattr (shell_terminal, e j-> tmodes);
       tcsetattr (shell_terminal, TCSADRAIN, e shell_tmodes);
     }	
/*colocando o processo em background*/

 
void put_job_in_background (trabalho * j, int cont)
     {
       / * Enviar o trabalho de um sinal de continuar, se necessário.   * /
       if (cont)
         if (kill (-j-> pgid, SIGCONT) <0)
           perror ("kill (SIGCONT)");
     }



#endif
